package com.neusoft.elmboot.service.Impl;

import java.util.Arrays;
import java.util.List;

import org.ansj.splitWord.analysis.ToAnalysis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.elmboot.mapper.BusinessMapper;
import com.neusoft.elmboot.mapper.UserMapper;
import com.neusoft.elmboot.po.Business;
import com.neusoft.elmboot.service.BusinessService;

@Service
public class BusinessServiceImpl implements BusinessService{
	
	@Autowired
	private BusinessMapper businessMapper;
	
	@Autowired
	private UserMapper userMapper;

	@Override
	public List<Business> listBusinessByOrderTypeId(Integer orderType){
		return businessMapper.listBusinessByOrderTypeId(orderType);
	}
	
	@Override
	public Business getBusinessById(Integer businessId) {
		return businessMapper.getBusinessById(businessId);
	}

	@Override
	public List<Business> listBusinessByWords(String words) {
		String analysisedText = ToAnalysis.parse(words).toStringWithOutNature();
		String[] wordsArray = analysisedText.split(",");
		List<String> wordsList = Arrays.asList(wordsArray);
		return businessMapper.listBusinessByWords(wordsList);
	}
	
	@Override
	public int createBusiness(Business business) {
		businessMapper.createBusiness(business);
		userMapper.becomeBusiness(business.getUserId());
		return business.getBusinessId();
	}
	
	@Override
	public int updateBusiness(Business business) {
		return businessMapper.updateBusiness(business);
	}
	
	@Override
	public Business getBusinessByUserId(String userId) {
		return businessMapper.getBusinessByUserId(userId);
	}
}
